using System.IO;

namespace Lottery.Client.SL
{
    public class StructBetData
    {
        public int LotteryID;
        public string PlayTypeID;
        public string PlayTypeName;
        public double SchemeMultiple;
        public string LotteryNumber;
        public double SumMoney;
        public StructBetData()
        {
            this.PlayTypeID = "";
            this.PlayTypeName = "";
            this.LotteryNumber = "";
        }
        public byte[] GetBytes()
        {
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
            binaryWriter.Write(this.LotteryID);
            binaryWriter.Write(this.PlayTypeID);
            binaryWriter.Write(this.PlayTypeName);
            binaryWriter.Write(this.SchemeMultiple);
            binaryWriter.Write(this.LotteryNumber);
            binaryWriter.Write(this.SumMoney);
            binaryWriter.Close();
            memoryStream.Close();
            return memoryStream.ToArray();
        }
        public static StructBetData GetBetData(byte[] bytes)
        {
            StructBetData result;
            try
            {
                StructBetData structBetData = new StructBetData();
                MemoryStream memoryStream = new MemoryStream(bytes);
                BinaryReader binaryReader = new BinaryReader(memoryStream);
                structBetData.LotteryID = binaryReader.ReadInt32();
                structBetData.PlayTypeID = binaryReader.ReadString();
                structBetData.PlayTypeName = binaryReader.ReadString();
                structBetData.SchemeMultiple = binaryReader.ReadDouble();
                structBetData.LotteryNumber = binaryReader.ReadString();
                structBetData.SumMoney = binaryReader.ReadDouble();
                binaryReader.Close();
                memoryStream.Close();
                result = structBetData;
            }
            catch
            {
                result = null;
            }
            return result;
        }
    }
}